<?php

/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Album
 * @copyright  Copyright 2006-2010 Webligo Developments
 * @license    http://www.socialengine.net/license/
 * @version    $Id: Delete.php 8427 2011-02-09 23:11:24Z john $
 * @author     John Boehr <j@webligo.com>
 */

/**
 * @category   Application_Extensions
 * @package    Album
 * @copyright  Copyright 2006-2010 Webligo Developments
 * @license    http://www.socialengine.net/license/
 */
class Wall_Form_List_Edit extends Engine_Form
{

    public $friendUsers;

    protected $_listName;
    protected $_selectedFriends;
  
    public function setSelectedFriends($selectedFriends)
    {
        $this->_selectedFriends = $selectedFriends;
        return $this;
    }
    
    public function setListName($listName)
    {
        $this->_listName = $listName;
        return $this;
    }
  
    public function init()
    {
        $translate = Zend_Registry::get('Zend_Translate');
        $viewer = Engine_Api::_()->user()->getViewer();
        $this->friendUsers = Engine_Api::_()->wall()->getViewerFriends($viewer);

        $this->setTitle($translate->translate('Edit List'))
                ->setMethod('POST')
                ->setAction($_SERVER['REQUEST_URI'])
                ->setAttrib('class', 'global_form_popup')
        ;

        $this->addElement('Text', 'list_name', array(
            'value' => $this->_listName,
            'label' => $translate->translate('List name'),
            'required' => true,
            'allowEmpty' => false,
            'validators' => array(
                array('NotEmpty', true),
                array('StringLength', true, array(1, 128)),
                array('Db_NoRecordExists', true, array(Engine_Db_Table::getTablePrefix() . 'wall_lists', 'list_name', '`user_id` = ' . $viewer->getIdentity()))
            ),
            'filters' => array(
                'StripTags',
                new Engine_Filter_Censor()
            )
        ));
        $this->list_name->getValidator('Db_NoRecordExists')->setMessage($translate->translate('You have already used this name, please use another one.'), 'recordFound');

//        // create selection list for types
//        $this->addElement('Select', 'list_type', array(
//            'label' => 'Type',
//            'multiOptions' => array(
//                'friend' => 'Friends',
//                'group' => 'Groups'
//            )
//        ));
        
        $temp = '<div id="friend-list"><table>';
        foreach ($this->friendUsers as $friend)
        {
            $temp .=
                '<tr name="friend-row" uid="' . $friend['id'] . '">'
                .'<td class="checkbox"><input type="checkbox" value=""/></td>'
                .'<td class="photo"><img src="' . $friend['photo'] . '"/>'
                .'<td class="name">' . $friend['name'] . '</td>'
                .'</tr>';
        }
        $temp .= '</table></div>';
        
        $this->addElement('Dummy', 'add_friends', array(
            'content' => $temp
        ));

        $this->addElement('Hidden', 'friend_array', array(
            'value' => $this->_selectedFriends,

        ));

        $this->addElement('Button', 'submit', array(
            'label' => $translate->translate('Edit List'),
            'ignore' => true,
            'decorators' => array('ViewHelper'),
            'type' => 'submit'
        ));

        $this->addElement('Cancel', 'cancel', array(
            'prependText' => ' '.$translate->translate('or').' ',
            'label' => $translate->translate('cancel'),
            'link' => true,
            'href' => '',
            'onclick' => 'parent.Smoothbox.close();',
            'decorators' => array(
                'ViewHelper'
            ),
        ));

        //$this->addDisplayGroup(array('execute', 'cancel'), 'buttons');
    }

}
